#include<bits/stdc++.h>
#define int long long 
using namespace std;

const int maxn = 105;
int arr[maxn][maxn];
bool vis[maxn][maxn];
int n, m;
int ans;
int temp;

int nx[] = {0, 0, 1, -1};
int ny[] = {1, -1, 0, 0};
void dfs(int x,int y){
	temp += arr[x][y];
	vis[x][y] = true;
	for (int i=0;i<4;i++) {
		int x1 = x + nx[i];
		int y1 = y + ny[i];
		if (x1<=0||x1>n||y1<=0||y1>m||vis[x1][y1]||arr[x1][y1]==0) {
			continue;
		}
		dfs(x1, y1);
	}
}

void solve(){
	cin >> n >> m;
	for (int i=1;i<=n;i++) {
		for (int j=1;j<=m;j++) {
			cin >> arr[i][j];
		}
	}
	for (int i=1;i<=n;i++) {
		for (int j=1;j<=m;j++) {
			if (!vis[i][j] && arr[i][j] != 0) {
				// 没有遍历过
				temp = 0;
				dfs(i, j);
				ans = max(ans, temp);
			}
		}
	}
	cout << ans << '\n';
}


signed main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	solve();
	return 0;
}
